package Day2025_04_03;

import java.util.ArrayList;
import java.util.List;

public class LeetCode78 {
    List<List<Integer>> ret;
    List<Integer> path;
    public List<List<Integer>> subsets(int[] nums) {
        ret = new ArrayList<>();
        path = new ArrayList<>();
        dfs (nums, 0);
//        dfs2 (nums, 0);
        return ret;
    }
    private void dfs (int[] nums, int pos) {
        ret.add(new ArrayList<>(path));
        for (int i = pos; i < nums.length; i++) {
            path.add(nums[i]);
            dfs (nums, i + 1);
            path.remove(path.size() - 1);
        }
    }
    private void dfs2 (int[] nums, int pos) {
        if (pos == nums.length) {
            ret.add(new ArrayList<>(path));
            return;
        }

        // 选
        path.add(nums[pos]);
        dfs2 (nums, pos + 1);

        // 恢复现场
        path.remove(path.size() - 1);

        // 不选
        dfs2 (nums, pos + 1);
    }
}
